﻿<UserControl x:Class="MaxStoreShop.ShopModule.DebtorRules.DebtorRuleEditor.DebtorRuleEditorView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
             xmlns:converters="clr-namespace:MaxStoreErp.Core.Converters;assembly=MaxStoreErp.Core"
             xmlns:converters1="clr-namespace:MaxStoreShop.Core.Converters;assembly=MaxStoreShop.Core"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:debtorRuleEditor="clr-namespace:MaxStoreShop.ShopModule.DebtorRules.DebtorRuleEditor"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:validators="clr-namespace:MaxStoreShop.Logic.Validators;assembly=MaxStoreShop.Logic"
             Style="{DynamicResource EditorStyle}"
             d:DataContext="{d:DesignInstance debtorRuleEditor:DebtorRuleEditorViewModel}"
             d:DesignHeight="300"
             d:DesignWidth="600"
             mc:Ignorable="d">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../../Resources/Shared.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <converters:NullImageConverter x:Key="NullImageConverter" />
            <converters1:MoneyEditorConverter x:Key="MoneyEditorConverter" />
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Border Margin="6,6,6,6"
                BorderBrush="Bisque"
                BorderThickness="1"
                CornerRadius="6"
                UseLayoutRounding="True">
            <Image MinWidth="100"
                   MinHeight="100"
                   MaxWidth="100"
                   Margin="1"
                   DataContext="{Binding SelectedItem}"
                   Source="{Binding Character.Photo,
                                    Converter={StaticResource NullImageConverter}}" />
        </Border>
        <Grid Grid.Column="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <TextBlock Margin="6"
                       VerticalAlignment="Center"
                       Text="Человек:" />

            <TextBlock Grid.Row="1"
                       Grid.Column="0"
                       Margin="6"
                       VerticalAlignment="Center"
                       Text="Предел долга:" />
            <TextBlock Grid.Row="2"
                       Grid.Column="0"
                       Margin="6"
                       VerticalAlignment="Center"
                       Text="Долг запрещен:" />
            <Grid Grid.Row="0" Grid.Column="1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <ComboBox Grid.Row="0"
                          Margin="6"
                          IsEditable="True"
                          IsTextSearchCaseSensitive="False"
                          IsTextSearchEnabled="True"
                          ItemsSource="{Binding Characters}">
                    <ComboBox.SelectedItem>
                        <Binding Mode="TwoWay"
                                 Path="SelectedItem.Character"
                                 UpdateSourceTrigger="PropertyChanged"
                                 ValidatesOnExceptions="True">
                            <Binding.ValidationRules>
                                <validators:ValueNotNullValidator />
                            </Binding.ValidationRules>
                        </Binding>
                    </ComboBox.SelectedItem>
                </ComboBox>
                <Button Grid.Column="1"
                        Margin="6"
                        Command="{Binding AddCharacterCommand}"
                        Content="Добавить..." />
            </Grid>

            <StackPanel Grid.Row="1"
                        Grid.Column="1"
                        Orientation="Horizontal">
                <controls:NumericUpDown MinWidth="100"
                                        Margin="6"
                                        HorizontalAlignment="Left"
                                        VerticalAlignment="Center"
                                        Interval="1"
                                        Minimum="0"
                                        Value="{Binding SelectedItem.MaxDebtSize,
                                                        Mode=TwoWay,
                                                        Converter={StaticResource MoneyEditorConverter}}" />
                <TextBlock Margin="6"
                           VerticalAlignment="Center"
                           Text="руб" />
            </StackPanel>
            <CheckBox Grid.Row="2"
                      Grid.Column="1"
                      Margin="6"
                      HorizontalAlignment="Left"
                      VerticalAlignment="Center"
                      IsChecked="{Binding SelectedItem.IsDebtDisabled,
                                          Mode=TwoWay,
                                          UpdateSourceTrigger=PropertyChanged}" />
        </Grid>
    </Grid>
</UserControl>
